package com.charging.controller.app;

import cn.hutool.core.util.StrUtil;
import com.charging.bean.Site;
import com.charging.config.config.BaseController;
import com.charging.config.result.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张子艺
 * @packge com.xbxkj.controller.admin
 * @data 2019-06-26 16:31
 * @project Metaphysics
 */
@RestController
@RequestMapping("/app/site")
@Api(value = "站点类", tags = {"站点类"})
public class SiteAppController extends BaseController {

    /**
     * 查询充电桩接口 和 数据库手动添加的充电桩    数据合并 包括优惠信息  优惠信息根据充电桩名字进行关联
     * @param
     * @return
     */

//        @RequestMapping(value = "/findSiteByLocal",method = RequestMethod.GET)
//        @ResponseBody
//        @ApiOperation(value = "查询站点")
//        @ApiImplicitParams({
//                @ApiImplicitParam(name="dimension",value="维度",dataType="string", paramType = "query"  ),
//                @ApiImplicitParam(name="longitude",value="经度",dataType="string", paramType = "query"  )
//        })
//    public ApiResult findSiteByLocal(String dimension,String longitude){
//            if(StrUtil.hasBlank(dimension)){
//                return  ApiResult.fail("请传入dimension字段");
//            }
//            if(StrUtil.hasBlank(longitude)){
//                return  ApiResult.fail("请传入longitude字段");
//            }
//return siteService.findSiteByLocal(dimension,longitude);
//    }


    /**
     * @return 筛选
     */
    @RequestMapping(value = "screen", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("筛选和搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimension", value = "维度", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "whole", value = "0全部,1优惠,2无优惠", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "distance", value = "距离", dataType = "String", paramType = "query")
    })
    public ApiResult screen(Integer whole, String dimension, String longitude, String address,Integer distance ) {
        System.out.println("address:"+address);
        System.out.println("whole:"+whole);
        System.out.println("distance:"+distance);
        if (StrUtil.hasBlank(dimension)) {
            return ApiResult.fail("请传入维度(dimension)字段");
        }

        if (StrUtil.hasBlank(longitude)) {
            return ApiResult.fail("请传入经度(longitude)字段");
        }
        if(whole==0 && distance==null && address==""){
            return siteService.findSiteByLocal(dimension, longitude);
        }
        if( address=="" && whole==0 && distance==0  ){
            return siteService.findSiteByLocal(dimension, longitude);
        }
        if(address=="" && whole!=0 && distance==0){
            List<Site> list = siteService.screen(whole, dimension, longitude,distance);
            return ApiResult.ok(list);
        }

        //如果优惠信息等于null并且距离等于null并且地址不等于空就是搜索
        if(whole==null && address!="" && distance==null){
            return ApiResult.ok(siteService.sousuo(address, dimension, longitude ));
        }
        //如果 优惠信息不等于0也不等于null 并且地址等于空 距离不等于空就是筛选有无优惠信息
        if(whole!= 0 && whole!=null && address=="" && distance!=null){
            List<Site> list = siteService.screen(whole, dimension, longitude,distance);
            return ApiResult.ok(list);
        }
        //如果 优惠信息等于0 并且地址等于空并且距离等于null那就查询所有
        if(whole==0 && address=="" && distance==null){
            return siteService.findSiteByLocal(dimension, longitude);
        }
        //如果
        if(whole==0 && address=="" && distance!=null){
            List<Site> list = siteService.screen(whole, dimension, longitude,distance);
            return ApiResult.ok(list);
        }
        if(whole==4 && address!="" && distance==null){
            return ApiResult.ok(siteService.sousuo(address, dimension, longitude ));
        }





        // whole==0 && address=="" && distance==null
        //




//        if(whole==4 && address!="" ){
//            return ApiResult.ok(siteService.sousuo(address, dimension, longitude ));
//        }
//        if (whole == null || address!="" ) {
//            List<Site> list = siteService.screen(whole, dimension, longitude,distance);
//            System.out.println("list:"+list);
//            return ApiResult.ok(list);
//        }
//        if (whole == 0) {
//            return siteService.findSiteByLocal(dimension, longitude);
//        }
//        if (whole!=null || whole!=0 || address=="" ){
//            List<Site> list = siteService.screen(whole, dimension, longitude,distance);
//            System.out.println("list:"+list);
//            return ApiResult.ok(list);
//        }
//        if(address=="" || address==null){
//            return siteService.findSiteByLocal(dimension, longitude);
//        }
//        if (address != null) {
//            return ApiResult.ok(siteService.sousuo(address, dimension, longitude ));
//        }


        List<Site> list = siteService.screen(whole, dimension, longitude,distance);
        System.out.println("list:"+list);
        return ApiResult.ok(list);
    }


    /**
     * @param name
     * @return 详情
     */
    @RequestMapping(value = "details",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dimension", value = "维度", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name="name",value="站点名称",dataType="string", paramType = "query"  )
    })
    public ApiResult details(String name,String dimension, String longitude){
        if (StrUtil.hasBlank(dimension)) {
            return ApiResult.fail("请传入维度(dimension)字段");
        }
        if (StrUtil.hasBlank(longitude)) {
            return ApiResult.fail("请传入经度(longitude)字段");
        }
        return ApiResult.ok(siteService.details(name,dimension,longitude));
    }








    /**
     * @param address
     * @return 搜索
     */
//    @RequestMapping(value = "sousuo",method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation(value = "搜索")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="dimension",value="维度",dataType="string", paramType = "query"  ),
//            @ApiImplicitParam(name="longitude",value="经度",dataType="string", paramType = "query"  ),
//            @ApiImplicitParam(name="address",value="地址",dataType="string", paramType = "query"  )
//    })
//    public ApiResult sousuo (String address,String dimension, String longitude){
//        if(StrUtil.hasBlank(dimension)){
//            return  ApiResult.fail("请传入维度(dimension)字段");
//        }
//        if(StrUtil.hasBlank(longitude)){
//            return  ApiResult.fail("请传入经度(longitude)字段");
//        }
//        if(StrUtil.hasBlank(address)){
//            return  ApiResult.fail("请传入地址(address)字段");
//        }
//        return ApiResult.ok(siteService.sousuo(address,dimension,longitude));
//    }




}